// pages/personal/personal.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userinfo:{}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.hideShareMenu({
      complete: (res) => {},
    })
    this.getData();
  },
  getData : function(){
    var context = this;
    wx.request({
      url: app.config.server + '/api/userinfo',
      header:{
        sessionkey:wx.getStorageSync('session_key')
      },
      success: res => {
        console.log('------------------------------',res);
        if(res.data.name == 'null'){
          res.data.name = '';
        }
        context.setData({
          userinfo:res.data
        })
        if((context.data.userinfo.name == '' || context.data.userinfo.name ==undefined) || (context.data.userinfo.telephone == '' || context.data.userinfo.telephone == undefined)){

        }else{
          var detail = wx.getStorageSync('course');
          if(detail.id != undefined){
            wx.showModal({
              title: '提示',
              content: '是否要继续购买"'+detail.title +'"课程?',
              success:function(res){
                if (res.confirm) {
                  console.log('用户点击确定')
                  var detail = wx.getStorageSync('course');
                    if(detail.id != undefined){
                      wx.redirectTo({
                        url: '/pages/Detailspage/Detailspage?id='+detail.id,
                      })
                    }
                  } else if (res.cancel) {
                  console.log('用户点击取消')
                  }
              }
            })
          }
        }
      }
    })

    var detail = wx.getStorageSync('course');
    console.log('xxxxxxxxxxxx',this.data.userinfo);
    console.log(detail);
    
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  
  navigate:function(e){
    wx.navigateTo({
      url: e.currentTarget.dataset.url,
    })
  },
})